#!/bin/ash
#BK 2007, original idea from sunburnt
#Lesser GPL licence v2 (/usr/share/doc/legal). 2007 www.puppylinux.com
#written for Puppy 2.16.
#/etc/rc.d/BOOTCONFIG has variable EXTRASFSLIST='kde.sfs devx_216.sfs'
# ...space-delimited list of .sfs files to be loaded.
# ...must be located at same place as the pup_save file (in /mnt/home)
#    or at '/' for full hd installation.
#v2.17
#/etc/rc.d/MODULESCONFIG has variables PCI_OVERRIDES, SKIPLIST
#that are read and managed by the BootManager.
#v4.02 bugfix, modules now .ko.gz.
#v4.02 /lib/modules/modules.dep.<kernver> no more.
#v403 yeslist_func, parameters may be added to modules.
#v409 bugfix, list of sfs files was picking up non-sfs files.
#v411 bugfix, when choose to add more than one module.
#v412 /etc/DISTRO_SPECS, renamed pup_xxx.sfs, pup_save.2fs etc.
#w001 pup files renamed to woofr001.sfs, woofsave.2fs.
#w007 renamed to woof-007.sfs
#w015 allow 6 extra sfs files, up from 3. w020 zdrv fix.
#w478 file prefix 'pup2' got screened out.
#v423 need to check sfs 3.x or 4.x.
#v424 do away with checkbox that overrides user choice and loads _nnn.sfs only.
#v424 advise of sfs-version-converter.
#100125 manage system services at bootup.
#100221 slight change to a message. 100301 add msg for lameSMBxplorer.
#100518 fixed showed wrong partition for /mnt/home.
#100607 kernel 2.6.27.47 has squashfs4.
#100710 if pupsave file is in a subdirectory, only look for extra sfs's in that subdirectory.
#100711 modify to look in both top dir and subdirectory.
#100809 some inappropriate sfs files were displaying as candidates in dual-pane window.
#100831 fix KERNELSUBVER for olpc people, have 'uname -r' returning version with '_'.
#100913 new simplified puppy filenames.
#101221 yaf-splash fix.
#110305 refine code for blacklist module.
#110422 DISTRO_VERSION variable now has dotted format. note, also now using full dotted version# in puppy filenames.
#110505 support sudo for non-root user.
#111011 now using pupdialog instead of Xdialog for sfs chooser.
#111015 support kernel 3.x.
#111113 roll back to Xdialog for sfs chooser. pupdialog limited items, some people have 100s sfs's.
#120201 rodin.s: internationalized.
#120323 replace 'xmessage' with 'pupmessage'.
#120527 shinobar's sfs-load on-the-fly pet has /etc/rc.d/BOOTCONFIG.save, sync it.
#120626 only offer to load sfs files if have layered f.s., mention sfs_load.
#121125 when install a Service Pack, DISTRO_VERSION gets bumped, however may still want to load devx*_<old-version>.sfs, remove filter.
#131126 zigbert: gui (gtkdialog) improvements.

[ "`whoami`" != "root" ] && exec sudo -A ${0} ${@} #110505

export TEXTDOMAIN=bootmanager
export OUTPUT_CHARSET=UTF-8
. gettext.sh

#reentrant.
#$1='' then run the main window.
#$1=extrasfs then run the extrasfs_func.
CLPARAM1="$1"
CLPARAM2="$2"

MY_SELF="$0"
CURRDIR="`pwd`"
. /etc/rc.d/PUPSTATE
. /etc/DISTRO_SPECS
#PUPPYVERSION="`cat /etc/puppyversion`"
KERNVER="`uname -r`"

[ ! -f /etc/rc.d/BOOTCONFIG ] && touch /etc/rc.d/BOOTCONFIG #v424
. /etc/rc.d/BOOTCONFIG #v424

if vercmp $KERNVER ge 3.0;then #111015
 SFSSTR='squashfs, version 4'
else
 KERNELSUBVER=`echo -n "$KERNVER" | cut -f 3 -d '.' | cut -f 1 -d '-' | cut -f 1 -d '_'` #v423 100831
 SUB_SUB_KERNELVER=`echo -n "$KERNVER" | cut -f 1 -d '-' | cut -f 4 -d '.'` #100607
 SFSSTR='squashfs, version 3' #v423
 [ $KERNELSUBVER -gt 28 ] && SFSSTR='squashfs, version 4' #v423
 [ $KERNELSUBVER -eq 27 ] && [ $SUB_SUB_KERNELVER -gt 46 ] && SFSSTR='squashfs, version 4' #100607
fi

#v3.02
. /etc/rc.d/MODULESCONFIG
DEFAULT_SERIAL="false"
DEFAULT_FAST="false"
[ "$BYPASSSERIALPROBING" = "yes" ] && DEFAULT_SERIAL="true"
[ "$FASTBOOTMODULESLIST" != "" ] && DEFAULT_FAST="true"

if [ "$PUPMODE" = "5" ];then
 pupmessage -bg '#FF8080' -title "$(gettext 'BootManager error')" "$(gettext 'You must shutdown and create a personal save file first.')"
 exit
fi

xEXTRASFSMNTPTx="" #100711
if [ "$PUP_HOME" = "" ];then #defined in PUPSTATE.
 EXTRASFSMNTPT='/'
 MSGx="`eval_gettext \"Note2: These files are at '/' (in \\\$PDEV1 partition)\"`"
 MSGz='/'
else
 EXTRASFSMNTPT="/initrd${PUP_HOME}"
 xHOMEPART="$PDEV1" #100518
 [ "$PUPSAVE" ] && xHOMEPART="`echo -n "$PUPSAVE" | cut -f 1 -d ','`" #100518
 #MSGx="Note2: These files are at /mnt/home (same as '${DISTRO_FILE_PREFIX}save')"
 MSGz='/mnt/home'
 #100711 modify to look in both top dir and subdirectory...
 #100710 if pupsave is in a subdirectory, only look in that...
 if [ "$PUPSAVE" ];then #this test probably not needed
  xPSUBDIR="`echo -n "$PUPSAVE" | cut -f 3 -d ',' | sed -e 's%/[^/]*$%%'`" #ex: sda3,ext2,/pup220/spupsave.2fs will return /pup220
  if [ "$xPSUBDIR" ];then
   MSGz="/mnt/home or /mnt/home${xPSUBDIR}"
   xEXTRASFSMNTPTx="/initrd${PUP_HOME}${xPSUBDIR}"'/*.sfs' #100711
  fi
 fi
 MSGx="`eval_gettext \"Note2: These files are at \\\${MSGz} (in \\\${xHOMEPART} partition)\"`" #100221 100518 100710
fi
#for multisession cd, extra sfs files have to be on the cd...
#v3.97 sfs files are at '/', saved with a session...
if [ "$PUPMODE" = "77" ];then
 MSGz='/'
  EXTRASFSMNTPT='/'
 xEXTRASFSMNTPTx="" #100711
  MSGx="$(gettext 'Note2: All SFS files have to get loaded into RAM from CD')"
fi

extrasfs_func() {

 echo -n "" > /tmp/bootmanager_sfs_dlglist
 UNMOUNTME=""
 #cd $EXTRASFSMNTPT
 #v409 lobster gets some non-sfs files in ALLSFSLIST ...i have no idea how, but
 #need an extra grep filter here... w007 new name woof-007.sfs ... w478 fix for 'pup2' prefix... 100809 bug fix...
 ALLSFSLIST="`ls -1 $EXTRASFSMNTPT/*.sfs $xEXTRASFSMNTPTx | grep '\.sfs$' | tr "\n" " "`"
 #cd $CURRDIR
 sync
 [ "$UNMOUNTME" != "" ] && umount $UNMOUNTME

 #eliminate other versions from list...
 BASEFIXEDSFSLIST=""; ITEMCNT=0
 rm -f /tmp/bootmanager_wrong_sfs_version 2>/dev/null #v423
 for ONESFS in $ALLSFSLIST
 do
  BASEONESFS="`basename $ONESFS`" #100711
  [ "`echo "$BASEONESFS" | grep '^zdrv'`" != "" ] && continue #100809
  [ "`echo "$BASEONESFS" | grep '^adrv'`" != "" ] && continue
  [ "`echo "$BASEONESFS" | grep '^ydrv'`" != "" ] && continue
  [ "`echo "$BASEONESFS" | grep '^pup_'`" != "" ] && continue #100809
  [ "`echo "$BASEONESFS" | grep "^${DISTRO_FILE_PREFIX}\\-[0-9][0-9][0-9]\\.sfs$"`" != "" ] && continue #100809
  [ "`echo "$BASEONESFS" | grep "^${DISTRO_FILE_PREFIX}[rz]"`" != "" ] && continue #100809
  #121125 when install a Service Pack, DISTRO_VERSION gets bumped, however may still want to load devx*_<old-version>.sfs,
  # so, remove this filter...
  [ "`echo "$BASEONESFS" | grep "^${DISTRO_PUPPYSFS}"`" != "" ] && continue #100913
  [ "`echo "$BASEONESFS" | grep "^${DISTRO_ZDRVSFS}"`" != "" ] && continue #100913
  #v423 eliminate wrong squashfs version...
  if [ "`disktype ${ONESFS} | grep "$SFSSTR"`" = "" ];then
   echo "$BASEONESFS" >> /tmp/bootmanager_wrong_sfs_version
   continue
  fi
  [ "`echo "$BASEFIXEDSFSLIST" | grep "$BASEONESFS"`" != "" ] && continue #100711 avoid duplicates.
  BASEFIXEDSFSLIST="$BASEFIXEDSFSLIST $BASEONESFS"
 done
 BASEALLSFSLIST="$BASEFIXEDSFSLIST"

 #compose list for xdialog listbox...
 for ONESFS in $BASEALLSFSLIST
 do
  if [ "$EXTRASFSLIST" = "" ];then
   DLGLIST="$DLGLIST $ONESFS $ONESFS off"
  else
   [ "`echo -n "$EXTRASFSLIST" | grep -v "$ONESFS"`" != "" ] && DLGLIST="$DLGLIST $ONESFS $ONESFS off"
  fi
 done
 for ONESFS in $EXTRASFSLIST
 do
  DLGLIST="$DLGLIST $ONESFS $ONESFS on"
 done

 #v423 let user know wrong sfs's...
 if [ -e /tmp/bootmanager_wrong_sfs_version ];then
  pupmessage -bg '#FFC0C0' "`eval_gettext \"NOTICE: The following SFS files located in directory \\\${MSGz}
are the wrong version for the current Linux kernel:\"`

`cat /tmp/bootmanager_wrong_sfs_version`

`eval_gettext \"The above files will be ignored.
The kernel requires \\\${SFSSTR}, SFS files.
Note, there is an SFS-version-converter in the Utility menu.\"`" &
 fi

 if [ "$DLGLIST" = "" ];then
  [ "$CLPARAM2" = "quiet" ] && return 1
  pupmessage -center -bg '#FFC0C0' "`eval_gettext \"Sorry, there are no SFS files in directory \\\$MSGz
You will need to download and place one there first.\"`"
  return 1
 fi

 #111113 revert to Xdialog...
 EXECME="Xdialog --wmclass \"module16\" --backtitle \"$(gettext 'Choose which SFS files are to be loaded at bootup.\n(top entry will be on top Unionfs layer)')\" --title \"$(gettext 'BootManager: SFS files')\" --left --stdout --separator \" \" --help \"`eval_gettext \"Please click the 'install' icon on the desktop for information about SFS files.\nYou will find an introduction, plus links to SFS files that can be downloaded.\n\nNote, the BootManager performs some filtering of the available SFS files,\nscreening out some that might have incorrect version number -- files of the\nformat '*_nnn.sfs' should be '*_\\\${DISTRO_VERSION}.sfs' to pass the filter.\"`\" --buildlist \"$(gettext 'Note1: No more than 6 SFS files in right-pane!')\n${MSGx}\" 0 0 8 $DLGLIST >/tmp/bmrettags.txt"
 eval ${EXECME}
 RETVAL=$?
 [ ! $RETVAL -eq 0 ] && return 1
 RETTAGS="`cat /tmp/bmrettags.txt`"
 RETTAGS="`echo -n "$RETTAGS" | sed -e 's/ $//g'`"

 [ ! -e /etc/rc.d/BOOTCONFIG ] && touch /etc/rc.d/BOOTCONFIG
 grep -v 'EXTRASFSLIST' /etc/rc.d/BOOTCONFIG > /tmp/BOOTCONFIG
 cat /tmp/BOOTCONFIG > /etc/rc.d/BOOTCONFIG
 echo "EXTRASFSLIST='${RETTAGS}'" >> /etc/rc.d/BOOTCONFIG

 #120527 shinobar's sfs-load on-the-fly pet has this, sync it...
 if [ -f /etc/rc.d/BOOTCONFIG.save ];then
  bPTN="s%^EXTRASFSLIST=.*%EXTRASFSLIST='${RETTAGS}'%"
  sed -i -e "$bPTN" /etc/rc.d/BOOTCONFIG.save
 fi

} #end extrasfs_func

blacklist_func() {
 #blacklisting of modules at bootup.
 . /etc/rc.d/MODULESCONFIG
 MODLIST=""
 xSKIPLIST="`echo -n "$SKIPLIST" | tr ' ' '\n' | sort -u | tr '\n' ' ' | tr -s ' '`" #110305
 LOADEDMODULES="`lsmod | grep -v '^Module' | cut -f 1 -d ' ' | sort | tr '\n' ' '`" #110305
 for ONEMOD in $LOADEDMODULES
 do
  MODLIST="$MODLIST $ONEMOD $ONEMOD off"
 done
 for ONEMOD in $xSKIPLIST
 do
  MODLIST="$MODLIST $ONEMOD $ONEMOD on"
 done
 EXECME="Xdialog --wmclass \"module16\" --title \"$(gettext 'BootManager: Module blacklist manager')\" --left --stdout --separator \" \" --buildlist \"$(gettext 'On the left pane are modules that are currently loaded.\n
On the right pane is the complete list of blacklisted modules.\n
If you want to prevent a module from loading, move it to the right\n
side, click OK, then reboot.\n
Note, if you want to find out further information about any module,\n
run PupScan (look in the System menu)\n
Note, you need to reboot for any change to take effect.')\" 0 0 8 $MODLIST >/tmp/skiprettags.txt"
 eval $EXECME
 RETVAL=$?
 [ ! $RETVAL -eq 0 ] && return 1
 SKIPLIST=" `cat /tmp/skiprettags.txt | tr '\n' ' '`"
 #now update /etc/rc.d/MODULESCONFIG...
 sed -i -e "s%^SKIPLIST=.*%SKIPLIST='${SKIPLIST}'%" /etc/rc.d/MODULESCONFIG #110305
} #end blacklist_func

yeslist_func() {
 #choose extra modules to load at bootup.
 /usr/lib/gtkdialog/box_splash -close never -text "$(gettext 'Please wait, processing...')" &
 X1PID=$!
 . /etc/rc.d/MODULESCONFIG
 MODLIST=""

old_slow_off_list(){
 #note, lsmod will show all modules with '-' as '_'...
 LOADEDMODULES=" `lsmod | grep -v '^Module' | cut -f 1 -d ' ' | tr '\n' ' '`"
 #v403 handles both .ko and .ko.gz modules...
 ALLMODULES="`cat /lib/modules/$KERNVER/modules.dep | cut -f 1 -d ':' | grep -o '[a-zA-Z0-9_-]*\.ko' | tr '\-' '_' | sort - | tr '\n' ' '`"
 for ONEMOD in $ALLMODULES
 do
  NAMEONLY="`basename $ONEMOD .ko`"
  MODPATTERN=" $NAMEONLY "
  #leave off list if already loaded...
  [ "`echo "$LOADEDMODULES" | grep "$MODPATTERN"`" != "" ] && continue
  MODPATTERN=' '"$NAMEONLY"'[ :]'
  #leave off left pane if already on right pane...
  [ "`echo "$ADDLIST" | grep "$MODPATTERN"`" != "" ] && continue
  MODLIST="$MODLIST $NAMEONLY $NAMEONLY off"
  done
} #old_slow_off_list

  LOADEDMODULES=`cut -f1 -d' ' /proc/modules`
  ALLMODULES=`cut -f 1 -d ':' /lib/modules/$KERNVER/modules.dep | grep -o '[a-zA-Z0-9_-]*\.ko' | tr '\-' '_' | sed 's%\.k.*$%%' | sort`
  ALLMODULES=`echo "$ALLMODULES" | /bin/grep -vw "$LOADEDMODULES"`
  ADDLIST_MOD_ONLY=`echo "$ADDLIST" | tr ' ' '\n' | sed 's%:.*%%;/^$/d'`
  ALLMODULES=`echo "$ALLMODULES" | /bin/grep -vw "$ADDLIST_MOD_ONLY"`
  ALLMODULES=`echo "$ALLMODULES" | sed 's%\(.*\)%& & off%'`
  MODLIST=`echo "$ALLMODULES" | tr '\n' ' '`
  #echo "$MODLIST" >&2
 for ONEMOD in $ADDLIST
 do
  NAMEONLY="$ONEMOD"
  xONEMOD="$ONEMOD"
  if [ `echo -n "$ONEMOD" | tr ':' ' ' | wc -w` -gt 1 ];then
   MPARAMS="`echo -n "$ONEMOD" | cut -f 2-9 -d ':' | tr ':' ' '`"
   NAMEONLY="`echo -n "$ONEMOD" | cut -f 1 -d ':'`"
   xONEMOD="$NAMEONLY $MPARAMS"
  fi
  MODPATTERN=" $NAMEOLY "
  #leave off list if already loaded...
  [ "`echo "$LOADEDMODULES" | grep "$MODPATTERN"`" != "" ] && continue
  MODLIST="$MODLIST $ONEMOD \"$xONEMOD\" on"
 done
 #echo >&2
 #echo "$MODLIST" >&2
 [ "$MODLIST" ] || : ##TODO something
 kill $X1PID 2>/dev/null
 EXECME="Xdialog --wmclass \"module16\" --title \"$(gettext 'BootManager: Module add-list manager')\" --left --stdout --separator \" \" --buildlist \"$(gettext 'On the left pane is the complete list of modules available to be\nused by Puppy (and not currently loaded).\nOn the right pane are modules that you have explicitly chosen to\nbe loaded at bootup (not auto-loaded by default).\nIf you want to force a module to load, move it to the right pane,\nclick OK button, then reboot Puppy.\nNote, if you want to find out further information about any module,\nrun PupScan (look in the System menu)')\" 0 0 8 $MODLIST >/tmp/yesrettags.txt"
 eval $EXECME
 RETVAL=$?
 [ ! $RETVAL -eq 0 ] && return 1
 cat /tmp/yesrettags.txt | tr ' ' '\n' | tr ':' ' ' > /tmp/modules_addlist_edit #v411
 Xdialog --backtitle "$(gettext "If you wish, add any required parameters to these modules\nExample: mmc_block major=179\nIf you don't know what this means, just click 'OK' button")"  --wmclass "module16" --title "$(gettext 'BootManager: Edit module addlist')" --left --stdout --no-cancel --editbox /tmp/modules_addlist_edit 0 0 > /tmp/modules_addlist_edit_out  #'geany
 [ $? -ne 0 ] && return 1
 ADDLIST="`cat /tmp/modules_addlist_edit_out`"
 ADDLIST=' '"`echo "$ADDLIST" | tr ' ' ':' | tr '\n' ' ' | tr -s ' '`"
 #ADDLIST=" `cat /tmp/yesrettags.txt | tr '\n' ' '`"
 #now update /etc/rc.d/MODULESCONFIG...
 grep -v '^ADDLIST' /etc/rc.d/MODULESCONFIG > /tmp/MODULESCONFIG
 mv -f /tmp/MODULESCONFIG /etc/rc.d/MODULESCONFIG
 echo "ADDLIST='${ADDLIST}'" >> /etc/rc.d/MODULESCONFIG
} #end yeslist_func

#  \"Sometimes two modules are eligible for the same hardware, and you need to choose\none of them. An example is the rt2500usb and rt73usb wireless networking modules\n-- with some hardware these are both eligible however our experience has been that\nthe rt73usb works better. For such a situation, create a line here, of format\nmodule1:module2, where you want module2 to have preference over module1.\nNote: an alternative approach is to blacklist the rt2500usb module (see main menu)\nhowever that is gross as it always prevents rt2500usb from loading.\"

preflist_func() {
 xPREFLIST="`echo -n "$PREFLIST" | sed -e 's/^ //' | tr ' ' '\n'`"
 echo "$xPREFLIST" > /tmp/bootmanager_preflist
 xxPREFLIST="`Xdialog --backtitle \"$(gettext 'Sometimes two modules are eligible for the same hardware,\n
and you need to choose one of them. Create a line here,\nof format module1:module2, where you want module2 to\nhave preference over module1.')\" --wmclass \"module16\" --title \"$(gettext 'BootManager: Module preference-list manager')\" --left --stdout --help \"$(gettext 'Sometimes two modules are eligible for the same hardware, and you need to choose\none of them. An example is the rt2500usb and rt73usb wireless networking modules\n-- with some hardware these are both eligible however our experience has been that\nthe rt73usb works better. For such a situation, create a line here, of format\nmodule1:module2, where you want module2 to have preference over module1.\nNote: an alternative approach is to blacklist the rt2500usb module (see main menu)\nhowever that is gross as it always prevents rt2500usb from loading.')\" --editbox /tmp/bootmanager_preflist 0 0`"
 if [ $? -eq 0 ];then
  NEWPREFLIST="`echo "$xxPREFLIST" | tr '\n' ' ' | sed -e 's/^/ /' | tr -s ' '`"
  grep -v '^PREFLIST' /etc/rc.d/MODULESCONFIG > /tmp/MODULESCONFIG
  mv -f /tmp/MODULESCONFIG /etc/rc.d/MODULESCONFIG
  echo "PREFLIST='${NEWPREFLIST}'" >> /etc/rc.d/MODULESCONFIG
 fi
} #end preflist_func

sysdaemons_func() { #100125
 osdcnt=0
 echo -n "" > /tmp/bootmanager_osd
 for ONESYSDAEMON in `find /etc/init.d -maxdepth 1 -type f | grep -v -E 'txt|pcmcia|alsa'`
 do
  osdcnt=`expr $osdcnt + 1`
  OSDNAME="`basename $ONESYSDAEMON`"
  xOSDNAME="`echo -n "$OSDNAME" | sed -e 's%^[0-9]%%' -e 's%^[0-9]%%'`" #remove any leading number.
  OSDDIR="`dirname $ONESYSDAEMON`"
  OSDDEFAULT='false'
  [ -x $ONESYSDAEMON ] && OSDDEFAULT='true'
  OSDDESCR=''
  case $xOSDNAME in
   alsa) OSDDESCR='('$(gettext 'ALSA sound server, required to play audio')')' ;;
   cups) OSDDESCR='('$(gettext 'CUPS printing, required to print')')' ;;
   messagebus) OSDDESCR='('$(gettext 'DBUS interprocess messaging, required by some apps')')' ;;
   rc.acpi) OSDDESCR='('$(gettext 'ACPI management, not essential')')' ;;
   slmodem) OSDDESCR='('$(gettext 'Only needed for certain Internet dialup modems')')' ;;
   sys_logger) OSDDESCR='('$(gettext 'Logs kernel & app. info. & error messages, not essential')')' ;;
   rc.smbqmsvc) OSDDESCR='('$(gettext 'only needed for quick mounting Samba shares in lameSMBxplorer')')' ;;
  esac
  OSDBOXES="${OSDBOXES} <checkbox><label>${xOSDNAME} ${OSDDESCR}</label><default>${OSDDEFAULT}</default><variable>OSDCHK_${osdcnt}_</variable></checkbox>"
  echo "OSDCHK_${osdcnt}_|${OSDDIR}|${OSDNAME}" >> /tmp/bootmanager_osd
 done
 if [ "`grep '/etc/rc.d/rc.firewall' /etc/rc.d/rc.local`" != "" ];then
  osdcnt=`expr $osdcnt + 1`
  OSDDEFAULT='false'
  [ -x /etc/rc.d/rc.firewall ] && OSDDEFAULT='true'
  OSDBOXES="${OSDBOXES} <checkbox><label>rc.firewall ($(gettext 'Firewall important security on Internet'))</label><default>${OSDDEFAULT}</default><variable>OSDCHK_${osdcnt}_</variable></checkbox>"
  echo "OSDCHK_${osdcnt}_|/etc/rc.d|rc.firewall" >> /tmp/bootmanager_osd
 fi
 #also offer udev management...
 osdcnt=`expr $osdcnt + 1`
 OSDDEFAULT='false'
 [ "`grep '^BACKENDON' /etc/eventmanager | grep 'true'`" != "" ] && OSDDEFAULT='true'
 OSDBOXES="${OSDBOXES} <checkbox><label>udev (`gettext \"Hardware hotplug detection -- see 'Help'\"`)</label><default>${OSDDEFAULT}</default><variable>OSDCHK_${osdcnt}_</variable></checkbox>"
 echo "OSDCHK_${osdcnt}_||udev" >> /tmp/bootmanager_osd

 export BootManager_Services='
<window title="'$(gettext 'BootManager - System services')'" icon-name="gtk-execute" default-height="400">
<vbox space-expand="true" space-fill="true">
  <frame '$(gettext 'System services')'>
    '"`/usr/lib/gtkdialog/xml_info 80 startup_services.svg 60 "$(gettext "Untick a checkbox to prevent service from running at startup")"`"'
    <hbox space-expand="true" space-fill="true">
    <vbox scrollable="true" shadow-type="0" border-width="10" space-expand="true" space-fill="true">
    '${OSDBOXES}'
    </vbox>
    </hbox>
  </frame>
  <hbox space-expand="false" space-fill="false">
    <button space-expand="false" space-fill="false">
      '"`/usr/lib/gtkdialog/xml_button-icon help`"'
      <label>'$(gettext 'Help')'</label>
      <action>cp /etc/init.d/README.txt /tmp/box_help; /usr/lib/gtkdialog/box_help "'$(gettext 'Startup services')'" &</action>
    </button>
    <text space-expand="true" space-fill="true"><label>""</label></text>
    <button space-expand="false" space-fill="false">
      <label>'$(gettext "Cancel")'</label>
      '"`/usr/lib/gtkdialog/xml_button-icon cancel`"'
      <action>exit:CANCEL</action>
    </button>
    <button space-expand="false" space-fill="false">
      <label>'$(gettext "Ok")'</label>
      '"`/usr/lib/gtkdialog/xml_button-icon ok`"'
      <action>exit:OK</action>
    </button>
  </hbox>
</vbox>
</window>'

 RETSTRING="`gtkdialog -p BootManager_Services`"
 [ "`echo "$RETSTRING" | grep 'EXIT' | grep 'OK'`" = "" ] && return
 while [ $osdcnt -gt 0 ];do
  OSDVAR="OSDCHK_${osdcnt}_"
  OSDDIR="`grep "$OSDVAR" /tmp/bootmanager_osd | cut -f 2 -d '|'`"
  OSDNAME="`grep "$OSDVAR" /tmp/bootmanager_osd | cut -f 3 -d '|'`"
  if [ "$OSDNAME" = "udev" ];then
   if [ "`echo "$RETSTRING" | grep "$OSDVAR" | grep 'true'`" != "" ];then
    if [ "`grep '^BACKENDON' /etc/eventmanager | grep 'false'`" != "" ];then
     pupmessage -center -bg orange "`gettext \"The EventManager will now be run, so that you can enable 'udev'.
You will need to tick the 'hotplug module/firmware loading' checkbox...\"`"
     eventmanager &
    fi
   else
    if [ "`grep '^BACKENDON' /etc/eventmanager | grep 'true'`" != "" ];then
     pupmessage -center -bg orange "`gettext \"The EventManager will now be run, so that you can disable 'udev'.
You will need to untick the 'hotplug module/firmware loading' checkbox...\"`"
     eventmanager &
    fi
   fi
  fi
  if [ "$OSDDIR" = "/etc/init.d" -o "$OSDDIR" = "/etc/rc.d" ];then
   if [ "`echo "$RETSTRING" | grep "$OSDVAR" | grep 'true'`" != "" ];then
    chmod 755 ${OSDDIR}/${OSDNAME}
   else
    chmod 644 ${OSDDIR}/${OSDNAME}
   fi
  fi
  osdcnt=`expr $osdcnt - 1`
 done

} #end sysdaemons_func

if [ "$CLPARAM1" = "extrasfs" ];then
 extrasfs_func
 exit

elif [ "$CLPARAM1" = "blacklist" ];then
 blacklist_func
 exit

elif [ "$CLPARAM1" = "yeslist" ];then
 yeslist_func
 exit

elif [ "$CLPARAM1" = "preflist" ];then
 preflist_func
 exit

elif [ "$CLPARAM1" = "sysdaemons" ];then #100125
 sysdaemons_func
 exit
fi

#120626 only offer to load sfs files if have layered f.s., mention sfs_load...
if [ -d /initrd ];then #PUPMODE=2, full hd install, will not have this.
    if [ "`cat /root/.packages/woof-installed-packages /root/.packages/user-installed-packages | grep '^sfs_load'`" != "" ];then
        SFSLOAD_XML="$(gettext "ALTERNATIVE: Shinobar's SFS_Load application will enable you to install SFS files on-the-fly, that is, load and unload them without having to reboot -- see the 'Setup' menu.")"
    #'geany
    fi
    SFSFRAME_XML='
    <frame '$(gettext 'Load SFS files')'>
      <vbox space-expand="true" space-fill="true">
        '"`/usr/lib/gtkdialog/xml_info scale package_sfs.svg 60 "$(gettext "Puppy has a file named") ${DISTRO_PUPPYSFS} $(gettext "that is always loaded. However, extra SFS files can be loaded at bootup, for example 'kde.sfs' to provide KDE applications, and 'devx.sfs' to provide everything for compiling C/C++ source. These can be thought of as 'combo packs' of many packages in one file.")" " " "${SFSLOAD_XML}"`"'
        <vbox space-expand="false" space-fill="false">
          <text height-request="20"><label>""</label></text>
          <hbox>
            <text><label>'$(gettext 'Choose which extra SFS files to load at bootup')'</label></text>
            <button>
              '"`/usr/lib/gtkdialog/xml_button-icon package_sfs.svg big`"'
              <action>'"$MY_SELF"' extrasfs &</action>
            </button>
          </hbox>
          <text height-request="5"><label>""</label></text>
        </vbox>
      </vbox>
    </frame>'
else
    if [ "`cat /root/.packages/woof-installed-packages /root/.packages/user-installed-packages  | grep '^sfs_load'`" != "" ];then
        SFSLOAD_XML="$(gettext "Shinobar's SFS_Load application will enable you to install SFS files -- see the 'Setup' menu.")"
    #'geany
    else
        SFSLOAD_XML="$(gettext "TECHNICAL: Clicking on an SFS file will open it, and it's contents can then be copied to /. It is recommended to use the '-a -f --remove-destination' parameters for the 'cp' command.")"
    #'geany
    fi
    SFSFRAME_XML='
    <frame '$(gettext 'Load SFS files')'>
      <vbox space-expand="true" space-fill="true">
        '"`/usr/lib/gtkdialog/xml_info scale package_sfs.svg 60 "$(gettext "NOTICE: As this is a full installation of Puppy without an initrd, SFS files cannot be loaded/unloaded at bootup. However, they can be permanently installed.")" " " "${SFSLOAD_XML}"`"'
      </vbox>
    </frame>'
fi

#######################################################

export BootManager='
<window title="'$(gettext 'Startup  Manager')'" icon-name="gtk-execute">
<vbox space-expand="true" space-fill="true">
  <notebook labels="'$(gettext 'Startup Apps')'|'$(gettext 'SFS-packages')'|'$(gettext 'Modules')'|'$(gettext 'Services')'">

    <frame '$(gettext 'Manage startup apps')'>
      <vbox space-expand="true" space-fill="true">
        '"`/usr/lib/gtkdialog/xml_info scale startup_app.svg 60 "$(gettext "Manage what apps are set to start when the graphical server (X) starts on your system. These apps include the notification icons in the system tray and some other hidden services that need the graphical server to be running.")"`"'
        <vbox space-expand="false" space-fill="false">
          <text height-request="20"><label>""</label></text>
          <hbox>
            <text><label>'$(gettext 'Manage startup apps')'</label></text>
            <button>
              '"`/usr/lib/gtkdialog/xml_button-icon startup_app.svg big`"'
              <action>wmstartups</action>
            </button>
          </hbox>
          <text height-request="5"><label>""</label></text>
        </vbox>
      </vbox>
    </frame>

    '"${SFSFRAME_XML}"'

    <frame '$(gettext 'Load kernel modules')'>
      <vbox space-expand="true" space-fill="true">
        '"`/usr/lib/gtkdialog/xml_info scale module.svg 60 "$(gettext "If a driver module did not get loaded, or the wrong one got loaded, or you want to 'blacklist' a module, this is the place. A common scenario is a driver got auto-loaded, for say your wireless network card, but you cannot or do not want to use it, and want some other module or want to use Ndiswrapper (to use the Windows driver).")"`"'
        <vbox space-expand="false" space-fill="false">
          <text height-request="20"><label>""</label></text>
          <hbox>
            <text><label>'$(gettext "'Blacklist' module")'</label></text>
            <button>
              '"`/usr/lib/gtkdialog/xml_button-icon module_no.svg big`"'
              <action>'"$MY_SELF"' blacklist &</action>
            </button>
          </hbox>
          <hbox>
            <text><label>'$(gettext 'Add new module')'</label></text>
            <button>
              '"`/usr/lib/gtkdialog/xml_button-icon module_yes.svg big`"'
              <action>'"$MY_SELF"' yeslist &</action>
            </button>
          </hbox>
          <hbox>
            <text><label>'$(gettext 'Give preference to one module over another')'</label></text>
            <button>
              '"`/usr/lib/gtkdialog/xml_button-icon module.svg big`"'
              <action>'"$MY_SELF"' preflist &</action>
            </button>
          </hbox>
          <text height-request="5"><label>""</label></text>
        </vbox>
      </vbox>
    </frame>

    <frame '$(gettext 'Manage system services')'>
      <vbox space-expand="true" space-fill="true">
        '"`/usr/lib/gtkdialog/xml_info scale startup_services.svg 60 "$(gettext "These are processes (applications) that are started at bootup and run continuously in the background. On slow PCs it may help to not run some of these.")"`"'
        <vbox space-expand="false" space-fill="false">
          <text height-request="20"><label>""</label></text>
          <hbox>
            <text><label>'$(gettext 'Choose which system services to run at startup')'</label></text>
            <button>
              '"`/usr/lib/gtkdialog/xml_button-icon startup_services.svg big`"'
              <action>'"$MY_SELF"' sysdaemons &</action>
            </button>
          </hbox>
          <text height-request="5"><label>""</label></text>
        </vbox>
      </vbox>
    </frame>
  </notebook>

  <hbox height-request="30" space-expand="false" space-fill="false">
    <button>'"`/usr/lib/gtkdialog/xml_button-icon quit`"'<label>'$(gettext 'Quit')'</label></button>
  </hbox>
</vbox>
</window>'

. /usr/lib/gtkdialog/xml_info gtk #build bg_pixmap for gtk-theme
RETSTRING="`gtkdialog -p BootManager`"

eval "$RETSTRING"

[ "$EXIT" = "abort" ] && exit


###END###
